﻿using Parylene_CVD.Commands;
using Parylene_CVD.DAL;
using Parylene_CVD.Model;
using Parylene_CVD.Model.DModels;
using Parylene_CVD.Service;
using Parylene_CVD.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;

namespace Parylene_CVD.ViewModel
{
    public class DeviceMonitorViewModel : ViewModelBase
    {
        public DeviceMonitorViewModel(NavigationService DataCurveViewNavigationService, NavigationService DataRecordViewNavigationService, NavigationService AlarmEventViewNavigationService, NavigationService HomeViewNavigationService) {
            SetDeviceName();
            DataRecordCommand = new NavigateCommand(DataRecordViewNavigationService);
            DataCurveCommand = new NavigateCommand(DataCurveViewNavigationService);
            AlarmEventCommand = new NavigateCommand(AlarmEventViewNavigationService);
            ExitCommand = new NavigateCommand(HomeViewNavigationService);
            TitleSet();
            //SetAllSetTemp();
            StartTimer();
        }


        public ICommand? MonitorCommand { get; }
        public ICommand? DataRecordCommand { get; }
        public ICommand? DataCurveCommand { get; }
        public ICommand? AlarmEventCommand { get; }
        public ICommand? ExitCommand { get; }

        // 设备名
        private string? _deviceName;
        public string? DeviceName
        {
            get => _deviceName;
            set
            {
                _deviceName = value;
                OnPropertyChanged(nameof(DeviceName));
            }
        }
        public void SetDeviceName()
        {
            if (GlobalVariables.CurDeviceName != null)
            {
                DeviceName = GlobalVariables.CurDeviceName;
            }
            else
            {
                MessageBox.Show("您没有选择任何设备", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private double? _coverRealTemp;   //炉盖实时温度
        public double? CoverRealTemp
        {
            get { return _coverRealTemp; }
            set
            {
                _coverRealTemp = value;
                OnPropertyChanged(nameof(CoverRealTemp));
            }
        }
        private double? _coverSetTemp;   //炉盖设置温度
        public double? CoverSetTemp
        {
            get { return _coverSetTemp; }
            set
            {
                _coverSetTemp = value;
                OnPropertyChanged(nameof(CoverSetTemp));
            }
        }
        private double? _tube1RealTemp;   //炉管1实时温度
        public double? Tube1RealTemp
        {
            get { return _tube1RealTemp; }
            set
            {
                _tube1RealTemp = value;
                OnPropertyChanged(nameof(Tube1RealTemp));
            }
        }
        private double? _tube2RealTemp;   //炉管2实时温度
        public double? Tube2RealTemp
        {
            get { return _tube2RealTemp; }
            set
            {
                _tube2RealTemp = value;
                OnPropertyChanged(nameof(Tube2RealTemp));
            }
        }
        private double? _tubeSetTemp1;   //炉管1设置温度
        public double? TubeSetTemp1
        {
            get { return _tubeSetTemp1; }
            set
            {
                _tubeSetTemp1 = value;
                OnPropertyChanged(nameof(TubeSetTemp1));
            }
        }
        private double? _tubeSetTemp2;   //炉管2设置温度
        public double? TubeSetTemp2
        {
            get { return _tubeSetTemp2; }
            set
            {
                _tubeSetTemp2 = value;
                OnPropertyChanged(nameof(TubeSetTemp2));
            }
        }
        private double? _evap1RealTemp;   //蒸发1实时温度
        public double? Evap1RealTemp
        {
            get { return _evap1RealTemp; }
            set
            {
                _evap1RealTemp = value;
                OnPropertyChanged(nameof(Evap1RealTemp));
            }
        }
        private double? _evap2RealTemp;   //蒸发2实时温度
        public double? Evap2RealTemp
        {
            get { return _evap2RealTemp; }
            set
            {
                _evap2RealTemp = value;
                OnPropertyChanged(nameof(Evap2RealTemp));
            }
        }
        private double? _evap3RealTemp;   //蒸发3实时温度
        public double? Evap3RealTemp
        {
            get { return _evap3RealTemp; }
            set
            {
                _evap3RealTemp = value;
                OnPropertyChanged(nameof(Evap3RealTemp));
            }
        }
        private double? _evapSetTemp1;   //蒸发1设置温度
        public double? EvapSetTemp1
        {
            get { return _evapSetTemp1; }
            set
            {
                _evapSetTemp1 = value;
                OnPropertyChanged(nameof(EvapSetTemp1));
            }
        }
        private double? _evapSetTemp2;   //蒸发2设置温度
        public double? EvapSetTemp2
        {
            get { return _evapSetTemp2; }
            set
            {
                _evapSetTemp2 = value;
                OnPropertyChanged(nameof(EvapSetTemp2));
            }
        }
        private double? _evapSetTemp3;   //蒸发3设置温度
        public double? EvapSetTemp3
        {
            get { return _evapSetTemp3; }
            set
            {
                _evapSetTemp3 = value;
                OnPropertyChanged(nameof(EvapSetTemp3));
            }
        }
        private double? _crak1RealTemp;   //裂解1实时温度
        public double? Crak1RealTemp
        {
            get { return _crak1RealTemp; }
            set
            {
                _crak1RealTemp = value;
                OnPropertyChanged(nameof(Crak1RealTemp));
            }
        }
        private double? _crak2RealTemp;   //裂解2实时温度
        public double? Crak2RealTemp
        {
            get { return _crak2RealTemp; }
            set
            {
                _crak2RealTemp = value;
                OnPropertyChanged(nameof(Crak2RealTemp));
            }
        }
        private double? _crak3RealTemp;   //裂解3实时温度
        public double? Crak3RealTemp
        {
            get { return _crak3RealTemp; }
            set
            {
                _crak3RealTemp = value;
                OnPropertyChanged(nameof(Crak3RealTemp));
            }
        }
        private double? _crakSetTemp1;   //裂解1设置温度
        public double? CrakSetTemp1
        {
            get { return _crakSetTemp1; }
            set
            {
                _crakSetTemp1 = value;
                OnPropertyChanged(nameof(CrakSetTemp1));
            }
        }
        private double? _crakSetTemp2;   //裂解2设置温度
        public double? CrakSetTemp2
        {
            get { return _crakSetTemp2; }
            set
            {
                _crakSetTemp2 = value;
                OnPropertyChanged(nameof(CrakSetTemp2));
            }
        }
        private double? _crakSetTemp3;   //裂解3设置温度
        public double? CrakSetTemp3
        {
            get { return _crakSetTemp3; }
            set
            {
                _crakSetTemp3 = value;
                OnPropertyChanged(nameof(CrakSetTemp3));
            }
        }
        private double? _auxRealTemp;   //辅热实时温度
        public double? AuxRealTemp
        {
            get { return _auxRealTemp; }
            set
            {
                _auxRealTemp = value;
                OnPropertyChanged(nameof(AuxRealTemp));
            }
        }
        private double? _auxSetTemp;   //辅热设置温度
        public double? AuxSetTemp
        {
            get { return _auxSetTemp; }
            set
            {
                _auxSetTemp = value;
                OnPropertyChanged(nameof(AuxSetTemp));
            }
        }
        private double? _freeRealTemp;   //冷冻实时温度
        public double? FreeRealTemp
        {
            get { return _freeRealTemp; }
            set
            {
                _freeRealTemp = value;
                OnPropertyChanged(nameof(FreeRealTemp));
            }
        }
        private double? _freeSetTemp;   //冷冻设置温度
        public double? FreeSetTemp
        {
            get { return _freeSetTemp; }
            set
            {
                _freeSetTemp = value;
                OnPropertyChanged(nameof(FreeSetTemp));
            }
        }
        private double? _binRealTemp;   //仓壁实时温度
        public double? BinRealTemp
        {
            get { return _binRealTemp; }
            set
            {
                _binRealTemp = value;
                OnPropertyChanged(nameof(BinRealTemp));
            }
        }
        private double? _binSetTemp;   //仓壁设置温度
        public double? BinSetTemp
        {
            get { return _binSetTemp; }
            set
            {
                _binSetTemp = value;
                OnPropertyChanged(nameof(BinSetTemp));
            }
        }
        private double? _coupRealTemp;   //偶联实时温度
        public double? CoupRealTemp
        {
            get { return _coupRealTemp; }
            set
            {
                _coupRealTemp = value;
                OnPropertyChanged(nameof(CoupRealTemp));
            }
        }
        private double? _coupSetTemp;   //偶联设置温度
        public double? CoupSetTemp
        {
            get { return _coupSetTemp; }
            set
            {
                _coupSetTemp = value;
                OnPropertyChanged(nameof(CoupSetTemp));
            }
        }
        private double? _back1RealTemp;   //备用1实时温度
        public double? Back1RealTemp
        {
            get { return _back1RealTemp; }
            set
            {
                _back1RealTemp = value;
                OnPropertyChanged(nameof(Back1RealTemp));
            }
        }
        private double? _back1SetTemp;   //备用1设置温度
        public double? Back1SetTemp
        {
            get { return _back1SetTemp; }
            set
            {
                _back1SetTemp = value;
                OnPropertyChanged(nameof(Back1SetTemp));
            }
        }
        private double? _back2RealTemp;   //备用2实时温度
        public double? Back2RealTemp
        {
            get { return _back2RealTemp; }
            set
            {
                _back2RealTemp = value;
                OnPropertyChanged(nameof(Back2RealTemp));
            }
        }
        private double? _back2SetTemp;   //备用2设置温度
        public double? Back2SetTemp
        {
            get { return _back2SetTemp; }
            set
            {
                _back2SetTemp = value;
                OnPropertyChanged(nameof(Back2SetTemp));
            }
        }
        private double? _chamRealPre;   //沉积室实时压力
        public double? ChamRealPre
        {
            get { return _chamRealPre; }
            set
            {
                _chamRealPre = value;
                OnPropertyChanged(nameof(ChamRealPre));
            }
        }
        private double? _pumpRealPre;   //真空泵实时压力
        public double? PumpRealPre
        {
            get { return _pumpRealPre; }
            set
            {
                _pumpRealPre = value;
                OnPropertyChanged(nameof(PumpRealPre));
            }
        }
        private bool? _isMotorOpen;   //旋转电机是否关闭
        public bool? IsMotorOpen
        {
            get { return _isMotorOpen; }
            set
            {
                _isMotorOpen = value;
                OnPropertyChanged(nameof(IsMotorOpen));
            }
        }
        private bool? _isAirBreakerValveOpen;   //破空阀是否关闭
        public bool? IsAirBreakerValveOpen
        {
            get { return _isAirBreakerValveOpen; }
            set
            {
                _isAirBreakerValveOpen = value;
                OnPropertyChanged(nameof(IsAirBreakerValveOpen));
            }
        }
        private bool? _isCoolingFan1Open;   //降温风扇1是否关闭
        public bool? IsCoolingFan1Open
        {
            get { return _isCoolingFan1Open; }
            set
            {
                _isCoolingFan1Open = value;
                OnPropertyChanged(nameof(IsCoolingFan1Open));
            }
        }
        private bool? _isCoolingFan2Open;   //降温风扇2是否关闭
        public bool? IsCoolingFan2Open
        {
            get { return _isCoolingFan2Open; }
            set
            {
                _isCoolingFan2Open = value;
                OnPropertyChanged(nameof(IsCoolingFan2Open));
            }
        }
        private bool? _isVacuumPumpOpen;   //真空泵是否关闭
        public bool? IsVacuumPumpOpen
        {
            get { return _isVacuumPumpOpen; }
            set
            {
                _isVacuumPumpOpen = value;
                OnPropertyChanged(nameof(IsVacuumPumpOpen));
            }
        }
        private bool? _isRootspumpOpen;   //罗茨泵是否关闭
        public bool? IsRootspumpOpen
        {
            get { return _isRootspumpOpen; }
            set
            {
                _isRootspumpOpen = value;
                OnPropertyChanged(nameof(IsRootspumpOpen));
            }
        }
        private bool? _isMainStatusOpen;   //主阀状态是否关闭
        public bool? IsMainStatusOpen
        {
            get { return _isMainStatusOpen; }
            set
            {
                _isMainStatusOpen = value;
                OnPropertyChanged(nameof(IsMainStatusOpen));
            }
        }
        private bool? _isAuxiliaryStatusOpen;   //副阀状态是否关闭
        public bool? IsAuxiliaryStatusOpen
        {
            get { return _isAuxiliaryStatusOpen; }
            set
            {
                _isAuxiliaryStatusOpen = value;
                OnPropertyChanged(nameof(IsAuxiliaryStatusOpen));
            }
        }

        private bool? _isFurnaceCoverHeatingOpen;   // 炉盖加热是否开启
        public bool? IsFurnaceCoverHeatingOpen
        {
            get { return _isFurnaceCoverHeatingOpen; }
            set
            {
                _isFurnaceCoverHeatingOpen = value;
                OnPropertyChanged(nameof(IsFurnaceCoverHeatingOpen));
            }
        }

        private bool? _isFurnaceTubeHeating1Open;   // 炉管1加热是否开启
        public bool? IsFurnaceTubeHeating1Open
        {
            get { return _isFurnaceTubeHeating1Open; }
            set
            {
                _isFurnaceTubeHeating1Open = value;
                OnPropertyChanged(nameof(IsFurnaceTubeHeating1Open));
            }
        }

        private bool? _isFurnaceTubeHeating2Open;   // 炉管2加热是否开启
        public bool? IsFurnaceTubeHeating2Open
        {
            get { return _isFurnaceTubeHeating2Open; }
            set
            {
                _isFurnaceTubeHeating2Open = value;
                OnPropertyChanged(nameof(IsFurnaceTubeHeating2Open));
            }
        }

        private bool? _isEvaporationHeating1Open;   // 蒸发1加热是否开启
        public bool? IsEvaporationHeating1Open
        {
            get { return _isEvaporationHeating1Open; }
            set
            {
                _isEvaporationHeating1Open = value;
                OnPropertyChanged(nameof(IsEvaporationHeating1Open));
            }
        }

        private bool? _isEvaporationHeating2Open;   // 蒸发2加热是否开启
        public bool? IsEvaporationHeating2Open
        {
            get { return _isEvaporationHeating2Open; }
            set
            {
                _isEvaporationHeating2Open = value;
                OnPropertyChanged(nameof(IsEvaporationHeating2Open));
            }
        }

        private bool? _isEvaporationHeating3Open;   // 蒸发3加热是否开启
        public bool? IsEvaporationHeating3Open
        {
            get { return _isEvaporationHeating3Open; }
            set
            {
                _isEvaporationHeating3Open = value;
                OnPropertyChanged(nameof(IsEvaporationHeating3Open));
            }
        }

        private bool? _isCrackingHeating1Open;   // 裂解1加热是否开启
        public bool? IsCrackingHeating1Open
        {
            get { return _isCrackingHeating1Open; }
            set
            {
                _isCrackingHeating1Open = value;
                OnPropertyChanged(nameof(IsCrackingHeating1Open));
            }
        }

        private bool? _isCrackingHeating2Open;   // 裂解2加热是否开启
        public bool? IsCrackingHeating2Open
        {
            get { return _isCrackingHeating2Open; }
            set
            {
                _isCrackingHeating2Open = value;
                OnPropertyChanged(nameof(IsCrackingHeating2Open));
            }
        }

        private bool? _isCrackingHeating3Open;   // 裂解3加热是否开启
        public bool? IsCrackingHeating3Open
        {
            get { return _isCrackingHeating3Open; }
            set
            {
                _isCrackingHeating3Open = value;
                OnPropertyChanged(nameof(IsCrackingHeating3Open));
            }
        }

        private bool? _isAuxiliaryHeatingHeatingOpen;   // 辅热加热是否开启
        public bool? IsAuxiliaryHeatingHeatingOpen
        {
            get { return _isAuxiliaryHeatingHeatingOpen; }
            set
            {
                _isAuxiliaryHeatingHeatingOpen = value;
                OnPropertyChanged(nameof(IsAuxiliaryHeatingHeatingOpen));
            }
        }

        private bool? _isFreezingHeatingOpen;   // 冷冻加热是否开启
        public bool? IsFreezingHeatingOpen
        {
            get { return _isFreezingHeatingOpen; }
            set
            {
                _isFreezingHeatingOpen = value;
                OnPropertyChanged(nameof(IsFreezingHeatingOpen));
            }
        }

        private bool? _isSilowallHeatingOpen;   // 仓壁加热是否开启
        public bool? IsSilowallHeatingOpen
        {
            get { return _isSilowallHeatingOpen; }
            set
            {
                _isSilowallHeatingOpen = value;
                OnPropertyChanged(nameof(IsSilowallHeatingOpen));
            }
        }

        private bool? _isCouplingHeatingOpen;   // 偶联加热是否开启
        public bool? IsCouplingHeatingOpen
        {
            get { return _isCouplingHeatingOpen; }
            set
            {
                _isCouplingHeatingOpen = value;
                OnPropertyChanged(nameof(IsCouplingHeatingOpen));
            }
        }

        private bool? _isBak1HeatingOpen;   // 备用1加热是否开启
        public bool? IsBak1HeatingOpen
        {
            get { return _isBak1HeatingOpen; }
            set
            {
                _isBak1HeatingOpen = value;
                OnPropertyChanged(nameof(IsBak1HeatingOpen));
            }
        }

        private bool? _isBak2HeatingOpen;   // 备用2加热是否开启
        public bool? IsBak2HeatingOpen
        {
            get { return _isBak2HeatingOpen; }
            set
            {
                _isBak2HeatingOpen = value;
                OnPropertyChanged(nameof(IsBak2HeatingOpen));
            }
        }

        private bool? _isFurnaceCoverHeatingClose;   // 炉盖加热是否关闭
        public bool? IsFurnaceCoverHeatingClose
        {
            get { return _isFurnaceCoverHeatingClose; }
            set
            {
                _isFurnaceCoverHeatingClose = value;
                OnPropertyChanged(nameof(IsFurnaceCoverHeatingClose));
            }
        }

        private bool? _isFurnaceTubeHeating1Close;   // 炉管1加热是否关闭
        public bool? IsFurnaceTubeHeating1Close
        {
            get { return _isFurnaceTubeHeating1Close; }
            set
            {
                _isFurnaceTubeHeating1Close = value;
                OnPropertyChanged(nameof(IsFurnaceTubeHeating1Close));
            }
        }

        private bool? _isFurnaceTubeHeating2Close;   // 炉管2加热是否关闭
        public bool? IsFurnaceTubeHeating2Close
        {
            get { return _isFurnaceTubeHeating2Close; }
            set
            {
                _isFurnaceTubeHeating2Close = value;
                OnPropertyChanged(nameof(IsFurnaceTubeHeating2Close));
            }
        }

        private bool? _isEvaporationHeating1Close;   // 蒸发1加热是否关闭
        public bool? IsEvaporationHeating1Close
        {
            get { return _isEvaporationHeating1Close; }
            set
            {
                _isEvaporationHeating1Close = value;
                OnPropertyChanged(nameof(IsEvaporationHeating1Close));
            }
        }

        private bool? _isEvaporationHeating2Close;   // 蒸发2加热是否关闭
        public bool? IsEvaporationHeating2Close
        {
            get { return _isEvaporationHeating2Close; }
            set
            {
                _isEvaporationHeating2Close = value;
                OnPropertyChanged(nameof(IsEvaporationHeating2Close));
            }
        }

        private bool? _isEvaporationHeating3Close;   // 蒸发3加热是否关闭
        public bool? IsEvaporationHeating3Close
        {
            get { return _isEvaporationHeating3Close; }
            set
            {
                _isEvaporationHeating3Close = value;
                OnPropertyChanged(nameof(IsEvaporationHeating3Close));
            }
        }

        private bool? _isCrackingHeating1Close;   // 裂解1加热是否关闭
        public bool? IsCrackingHeating1Close
        {
            get { return _isCrackingHeating1Close; }
            set
            {
                _isCrackingHeating1Close = value;
                OnPropertyChanged(nameof(IsCrackingHeating1Close));
            }
        }

        private bool? _isCrackingHeating2Close;   // 裂解2加热是否关闭
        public bool? IsCrackingHeating2Close
        {
            get { return _isCrackingHeating2Close; }
            set
            {
                _isCrackingHeating2Close = value;
                OnPropertyChanged(nameof(IsCrackingHeating2Close));
            }
        }

        private bool? _isCrackingHeating3Close;   // 裂解3加热是否关闭
        public bool? IsCrackingHeating3Close
        {
            get { return _isCrackingHeating3Close; }
            set
            {
                _isCrackingHeating3Close = value;
                OnPropertyChanged(nameof(IsCrackingHeating3Close));
            }
        }

        private bool? _isAuxiliaryHeatingHeatingClose;   // 辅热加热是否关闭
        public bool? IsAuxiliaryHeatingHeatingClose
        {
            get { return _isAuxiliaryHeatingHeatingClose; }
            set
            {
                _isAuxiliaryHeatingHeatingClose = value;
                OnPropertyChanged(nameof(IsAuxiliaryHeatingHeatingClose));
            }
        }


        private bool? _isSilowallHeatingClose;   // 仓壁加热是否关闭
        public bool? IsSilowallHeatingClose
        {
            get { return _isSilowallHeatingClose; }
            set
            {
                _isSilowallHeatingClose = value;
                OnPropertyChanged(nameof(IsSilowallHeatingClose));
            }
        }

        private bool? _isCouplingHeatingClose;   // 偶联加热是否关闭
        public bool? IsCouplingHeatingClose
        {
            get { return _isCouplingHeatingClose; }
            set
            {
                _isCouplingHeatingClose = value;
                OnPropertyChanged(nameof(IsCouplingHeatingClose));
            }
        }

        private bool? _isBak1HeatingClose;   // 备用1加热是否关闭
        public bool? IsBak1HeatingClose
        {
            get { return _isBak1HeatingClose; }
            set
            {
                _isBak1HeatingClose = value;
                OnPropertyChanged(nameof(IsBak1HeatingClose));
            }
        }

        private bool? _isBak2HeatingClose;   // 备用2加热是否关闭
        public bool? IsBak2HeatingClose
        {
            get { return _isBak2HeatingClose; }
            set
            {
                _isBak2HeatingClose = value;
                OnPropertyChanged(nameof(IsBak2HeatingClose));
            }
        }



        /// <summary>
        /// 从数据库根据当前页面设备名查询对应的参数设置值，为当前页面参数赋值
        /// </summary>
        public void SetAllSetTemp()
        {
            DeviceDAL deviceDAL = new DeviceDAL();
            int deviceID =  deviceDAL.GetDevice("DeviceName = '" + DeviceName + "'", "")[0].DeviceId;
            DeviceCoatingParametersDAL deviceCoatingParametersDAL = new DeviceCoatingParametersDAL();
            List<DeviceCoatingParameters> alldeviceCoatingParameters =  deviceCoatingParametersDAL.GetDeviceCoatingParameters("DeviceID = " + deviceID, "");
            if (alldeviceCoatingParameters.Count == 1) {
                DeviceCoatingParameters deviceCoatingParameters = alldeviceCoatingParameters[0];
                CoverSetTemp = deviceCoatingParameters.LidTempSetPoint;
                TubeSetTemp1 = deviceCoatingParameters.TubeTempSetPoint;
                EvapSetTemp1 = deviceCoatingParameters.EvapTempSetPoint;
                CrakSetTemp1 = deviceCoatingParameters.CrackTempSetPoint;
                AuxSetTemp = deviceCoatingParameters.AuxHeatTempSetPoint;
                FreeSetTemp = deviceCoatingParameters.FreezeTempSetPoint;
                BinSetTemp = deviceCoatingParameters.WallTempSetPoint;
                CoupSetTemp = deviceCoatingParameters.CoupleTempSetPoint;
                Back1SetTemp = deviceCoatingParameters.BackupTempSetPoint1;
                Back2SetTemp = deviceCoatingParameters.BackupTempSetPoint2;
            }
            else
            {
                MessageBox.Show("设备信息同步异常，请联系管理人员");
                return;
            }
            
            
        }

        /// <summary>
        /// 根据全局变量接收的数据得到对应设备的数据  然后为界面上所有实时数据赋值  在定时器中绑定此方法，一秒钟执行一次
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void SetAllRealData(object sender, EventArgs e)
        {
            var targetDevice = GlobalVariables.deviceWithStatuses?.FirstOrDefault(device => device.DeviceName == DeviceName);
            // 判断设备状态为镀膜中或者待机才为实时数据赋值
            if (targetDevice.IsCoating || targetDevice.IsStandby) {
                RealTimeData data = DeviceRealDataTools.GetDeviceData(DeviceName);
                if (data != null)
                {
                    CoverRealTemp = data.FurnaceCoverTemperature;
                    Tube1RealTemp = data.FurnaceTubeTemperature1;
                    Tube2RealTemp = data.FurnaceTubeTemperature2;
                    Evap1RealTemp = data.EvaporationTemperature1;
                    Evap2RealTemp = data.EvaporationTemperature2;
                    Evap3RealTemp = data.EvaporationTemperature3;
                    Crak1RealTemp = data.CrackingTemperature1;
                    Crak2RealTemp = data.CrackingTemperature2;
                    Crak3RealTemp = data.CrackingTemperature3;
                    AuxRealTemp = data.AuxiliaryHeatingTemperature;
                    FreeRealTemp = data.FreezingTemperature;
                    BinRealTemp = data.SilowallTemperature;
                    CoupRealTemp = data.CouplingTemperature;
                    Back1RealTemp = data.Bak1Temp;
                    Back2RealTemp = data.Bak2Temp;
                    ChamRealPre = data.BinPressure;
                    PumpRealPre = data.PumpPressure;
                    IsMotorOpen = data.IsMotorOpen;
                    IsAirBreakerValveOpen = data.IsAirBreakerValveOpen;
                    IsCoolingFan1Open = data.IsCoolingFan1Open;
                    IsCoolingFan2Open = data.IsCoolingFan2Open;
                    IsVacuumPumpOpen = data.IsVacuumPumpOpen;
                    IsRootspumpOpen = data.IsRootspumpOpen;
                    IsMainStatusOpen = data.IsMainStatusOpen;
                    IsAuxiliaryStatusOpen = data.IsAuxiliaryStatusOpen;

                    CoverSetTemp = data.FurnaceCoverTemperatureSetValue;
                    TubeSetTemp1 = data.FurnaceTubeTemperature1SetValue;
                    TubeSetTemp2 = data.FurnaceTubeTemperature2SetValue;
                    EvapSetTemp1 = data.EvaporationTemperature1SetValue;
                    EvapSetTemp2 = data.EvaporationTemperature2SetValue;
                    EvapSetTemp3 = data.EvaporationTemperature3SetValue;
                    CrakSetTemp1 = data.CrackingTemperature1SetValue;
                    CrakSetTemp2 = data.CrackingTemperature2SetValue;
                    CrakSetTemp3 = data.CrackingTemperature3SetValue;
                    AuxSetTemp = data.AuxiliaryHeatingTemperatureSetValue;
                    FreeSetTemp = data.FreezingTemperatureSetValue;
                    BinSetTemp = data.SilowallTemperatureSetValue;
                    CoupSetTemp = data.CouplingTemperatureSetValue;
                    Back1SetTemp = data.Bak1TempSetValue;
                    Back2SetTemp = data.Bak2TempSetValue;
                    if (data.IsHeating.GetValueOrDefault(false))
                    {
                        if (data.IsFurnaceCoverHeatingOpen.GetValueOrDefault(false))
                        {
                            IsFurnaceCoverHeatingOpen = true;
                            IsFurnaceCoverHeatingClose = false;
                        }
                        else
                        {
                            IsFurnaceCoverHeatingOpen = false;
                            IsFurnaceCoverHeatingClose = true;
                        }

                        if (data.IsFurnaceTubeHeating1Open.GetValueOrDefault(false))
                        {
                            IsFurnaceTubeHeating1Open = true;
                            IsFurnaceTubeHeating1Close = false;
                        }
                        else
                        {
                            IsFurnaceTubeHeating1Open = false;
                            IsFurnaceTubeHeating1Close = true;
                        }

                        if (data.IsFurnaceTubeHeating2Open.GetValueOrDefault(false))
                        {
                            IsFurnaceTubeHeating2Open = true;
                            IsFurnaceTubeHeating2Close = false;
                        }
                        else
                        {
                            IsFurnaceTubeHeating2Open = false;
                            IsFurnaceTubeHeating2Close = true;
                        }

                        if (data.IsEvaporationHeating1Open.GetValueOrDefault(false))
                        {
                            IsEvaporationHeating1Open = true;
                            IsEvaporationHeating1Close = false;
                        }
                        else
                        {
                            IsEvaporationHeating1Open = false;
                            IsEvaporationHeating1Close = true;
                        }

                        if (data.IsEvaporationHeating2Open.GetValueOrDefault(false))
                        {
                            IsEvaporationHeating2Open = true;
                            IsEvaporationHeating2Close = false;
                        }
                        else
                        {
                            IsEvaporationHeating2Open = false;
                            IsEvaporationHeating2Close = true;
                        }

                        if (data.IsEvaporationHeating3Open.GetValueOrDefault(false))
                        {
                            IsEvaporationHeating3Open = true;
                            IsEvaporationHeating3Close = false;
                        }
                        else
                        {
                            IsEvaporationHeating3Open = false;
                            IsEvaporationHeating3Close = true;
                        }

                        if (data.IsCrackingHeating1Open.GetValueOrDefault(false))
                        {
                            IsCrackingHeating1Open = true;
                            IsCrackingHeating1Close = false;
                        }
                        else
                        {
                            IsCrackingHeating1Open = false;
                            IsCrackingHeating1Close = true;
                        }

                        if (data.IsCrackingHeating2Open.GetValueOrDefault(false))
                        {
                            IsCrackingHeating2Open = true;
                            IsCrackingHeating2Close = false;
                        }
                        else
                        {
                            IsCrackingHeating2Open = false;
                            IsCrackingHeating2Close = true;
                        }

                        if (data.IsCrackingHeating3Open.GetValueOrDefault(false))
                        {
                            IsCrackingHeating3Open = true;
                            IsCrackingHeating3Close = false;
                        }
                        else
                        {
                            IsCrackingHeating3Open = false;
                            IsCrackingHeating3Close = true;
                        }

                        if (data.IsAuxiliaryHeatingHeatingOpen.GetValueOrDefault(false))
                        {
                            IsAuxiliaryHeatingHeatingOpen = true;
                            IsAuxiliaryHeatingHeatingClose = false;
                        }
                        else
                        {
                            IsAuxiliaryHeatingHeatingOpen = false;
                            IsAuxiliaryHeatingHeatingClose = true;
                        }

                        if (data.IsFreezingHeatingOpen.GetValueOrDefault(false))
                        {
                            IsFreezingHeatingOpen = true;
                        }
                        else
                        {
                            IsFreezingHeatingOpen = false;
                        }

                        if (data.IsSilowallHeatingOpen.GetValueOrDefault(false))
                        {
                            IsSilowallHeatingOpen = true;
                            IsSilowallHeatingClose = false;
                        }
                        else
                        {
                            IsSilowallHeatingOpen = false;
                            IsSilowallHeatingClose = true;
                        }

                        if (data.IsCouplingHeatingOpen.GetValueOrDefault(false))
                        {
                            IsCouplingHeatingOpen = true;
                            IsCouplingHeatingClose = false;
                        }
                        else
                        {
                            IsCouplingHeatingOpen = false;
                            IsCouplingHeatingClose = true;
                        }

                        if (data.IsBak1HeatingOpen.GetValueOrDefault(false))
                        {
                            IsBak1HeatingOpen = true;
                            IsBak1HeatingClose = false;
                        }
                        else
                        {
                            IsBak1HeatingOpen = false;
                            IsBak1HeatingClose = true;
                        }

                        if (data.IsBak2HeatingOpen.GetValueOrDefault(false))
                        {
                            IsBak2HeatingOpen = true;
                            IsBak2HeatingClose = false;
                        }
                        else
                        {
                            IsBak2HeatingOpen = false;
                            IsBak2HeatingClose = true;
                        }

                    }

                }
            }
            
        }
        /// <summary>
        /// 开启定时器读取实时数据
        /// </summary>
        public void StartTimer()
        {
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += SetAllRealData;
            timer.Start();
        }

        public string Monitor { get; set; }
        public string Insulation { get; set; }
        public string Heating { get; set; }
        public string Name { get; set; }
        public string Lid { get; set; }
        public string STemp { get; set; }
        public string RTemp { get; set; }
        public string Bin { get; set; }
        public string ColdTrap { get; set; }
        public string Pump { get; set; }
        public string Chamber { get; set; }
        public string Coup { get; set; }
        public string Pyro { get; set; }
        public string Lid1 { get; set; }
        public string Evap { get; set; }
        public string Tube { get; set; }
        public string Exit { get; set; }
        public string Cover { get; set; }
        public string Tube1 { get; set; }
        public string Tube2 { get; set; }
        public string Evapor1 { get; set; }
        public string Evapor2 { get; set; }
        public string Evapor3 { get; set; }
        public string Crack1 { get; set; }
        public string Crack2 { get; set; }
        public string Crack3 { get; set; }
        public string Aux { get; set; }
        public string Freeze { get; set; }
        public string Silowall { get; set; }
        public string Coupling { get; set; }
        public string FreezeSw { get; set; }
        public string Motor { get; set; }
        public string AirBreakerValve { get; set; }
        public string CoolingFan1 { get; set; }
        public string CoolingFan2 { get; set; }
        public string VacuumPump { get; set; }
        public string Rootspump { get; set; }
        public string RPressure { get; set; }
        public string MainStatus { get; set; }
        public string AuxiliaryStatus { get; set; }
        public string Backup1 { get; set; }
        public string Backup2 { get; set; }

        private void TitleSet()
        {
            Monitor = "监视界面";
            Name = "名称";
            Lid = "炉盖温度\n     ℃";
            RTemp = "实时温度";
            STemp = "设定温度";
            Bin = "沉积压力";
            ColdTrap = "冷阱温度\n     ℃";
            Pump = "真空泵压力";
            Chamber = "舱内压力\n  Pa";
            Coup = "偶联温度\n    ℃";
            Aux = "辅热温度";
            Pyro = "裂解温度\n    ℃";
            Lid1 = "炉盖温度\n    ℃";
            Evap = "蒸发温度\n    ℃";
            Tube1 = "炉管温度1";
            Tube2 = "炉管温度2";
            Evapor1 = "蒸发温度1";
            Evapor2 = "蒸发温度2";
            Evapor3 = "蒸发温度3";
            Crack1 = "裂解温度1";
            Crack2 = "裂解温度2";
            Crack3 = "裂解温度3";
            Freeze = "冷冻温度";
            Silowall = "仓壁温度";
            Coupling = "偶联温度";
            Backup1 = "备用温度1";
            Backup2 = "备用温度2";

            Exit = "退出";
            Cover = "炉盖温度";
            Tube1 = "炉管温度1";
            Insulation = "保温";
            Heating = "加热";
            FreezeSw = "冷冻机开关";

            Motor = "旋转电机开关";
            AirBreakerValve = "破空阀开关";
            CoolingFan1 = "降温风扇1开关";
            CoolingFan2 = "降温风扇2开关";
            VacuumPump = "真空泵开关";
            Rootspump = "罗茨泵开关";
            RPressure = "实时压力";
            MainStatus = "主阀状态";
            AuxiliaryStatus = "副阀状态";
        }
    }
}
